package cn.jobstart.service.impl;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import cn.jobstart.modelExt.AdminPermissionGroupExt;
import cn.jobstart.dao.IAdminPermissionGroupDao;
import cn.jobstart.searchExt.AdminPermissionGroupSearchExt;
import cn.jobstart.pubInter.IBaseDao;
import cn.jobstart.pubInter.AbstractBaseService;
import cn.jobstart.service.IAdminPermissionGroupService;
import lombok.extern.slf4j.Slf4j;
import java.util.List;
import java.util.stream.Collectors;
import cn.jobstart.pubInter.exception.SkException;
import cn.jobstart.common.StringUtil;

/**
*    @author sunke
*    @Date 2023-09-06 15:00:20
*    @description AdminPermissionGroupService      员工权限组
*/
@Service(value = "adminPermissionGroupService")
@Slf4j
public class AdminPermissionGroupServiceImpl extends AbstractBaseService<AdminPermissionGroupExt, AdminPermissionGroupSearchExt,String> implements IAdminPermissionGroupService {

    @Resource(name = "adminPermissionGroupDao")
    private IAdminPermissionGroupDao adminPermissionGroupDao;

    @Override
    public IBaseDao<AdminPermissionGroupExt, AdminPermissionGroupSearchExt,String> getDao() {
        return adminPermissionGroupDao;
    }



    @Override
    public void clearByAdminId(String adminId) {
        if (StringUtil.isNullOrEmpty(adminId)) {
            return;
        }

        try {
            batchDeleteBySearch(AdminPermissionGroupSearchExt.getInstance().setStaffIdEq(adminId));
        } catch (SkException e) {

        }

    }

    @Override
    public List<AdminPermissionGroupExt> getListByAdminId(String adminId) {

        if (StringUtil.isNullOrEmpty(adminId)) {
            return null;
        }

        try {
            return getAllList(AdminPermissionGroupSearchExt.getInstance().setStaffIdEq(adminId));
        } catch (SkException e) {

        }


        return null;
    }


    @Override
    public List<String> getGroupIdsByAdminId(String adminId) {

        List<AdminPermissionGroupExt> list = getListByAdminId(adminId);
        if (StringUtil.isNullOrEmpty(list)) {
            return null;
        }

        return list.stream().map(AdminPermissionGroupExt::getGroupId).distinct().collect(Collectors.toList());
    }
}